package com.github.zzay.user.feign.fallback;

import com.github.zzay.common.core.model.ResponseBean;
import com.github.zzay.user.dto.UserDto;
import com.github.zzay.user.feign.UserServiceClient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * @author zzay
 * @className UserServiceClientFallbackImpl
 * @description User Service Client Fallback Factory Implementation
 * @create 2022/06/06 15:11
 */
@Slf4j
@Data
@Component
public class UserServiceClientFallbackImpl implements UserServiceClient {

    /**
     * Throwable
     */
    private Throwable throwable;

    /**
     * 获取当前用户的信息
     *
     * @return 包含用户详细信息的响应Bean
     */
    @Override
    public ResponseBean<UserDto> info() {
        log.error("OpenFeign getUserInfo failed", throwable);
        return null;
    }

    /**
     * 根据用户名获取用户详细信息
     *
     * @param identifier identifier
     * @return 包含用户详细信息的响应 Bean
     */
    @Override
    public ResponseBean getUserByIdentifier(String identifier) {
        log.error("OpenFeign getUserByIdentifier failed: {}, {}", identifier, throwable);
        return null;
    }

    /**
     * 根据用户 id 获取用户
     *
     * @param ids ids
     * @return 包含用户详细信息列表的响应 Bean
     */
    @Override
    public ResponseBean getUserById(Long[] ids) {
        log.error("OpenFeign getUserById failed: {}, {}", ids, throwable);
        return null;
    }

    /**
     * 注册用户
     *
     * @param userDto userDto
     * @return 包含请求处理结果的响应 Bean
     */
    @Override
    public ResponseBean registerUser(UserDto userDto) {
        log.error("OpenFeign registerUser failed: {}, {}", userDto.getUsername(), throwable);
        return null;
    }

    /**
     * 查询用户数量
     *
     * @param userDto userDto
     * @return 包含用户数量的响应 Bean
     */
    @Override
    public ResponseBean getUserCount(UserDto userDto) {
        log.error("OpenFeign getUserCount failed: {}, {}", userDto, throwable);
        return new ResponseBean(HttpStatus.BAD_REQUEST.value(), "failed", 0);
    }

}
